%%% -------------------------------------------------------------------
%%%
%%% http://www.9miao.com
%%% -------------------------------------------------------------------
%%% -------------------------------------------------------------------
%%% Author  : MacX
%%% Description :
%%%
%%% Created : 2011-3-28
%%% -------------------------------------------------------------------
-module(answer_sup).

-behaviour(supervisor).
%% --------------------------------------------------------------------
%% Include files
%% --------------------------------------------------------------------

%% --------------------------------------------------------------------
%% External exports
%% --------------------------------------------------------------------
-export([start_link/0,start_child/2,stop_child/0]).

%% --------------------------------------------------------------------
%% Internal exports
%% --------------------------------------------------------------------
-export([
	 init/1
        ]).

%% --------------------------------------------------------------------
%% Macros
%% --------------------------------------------------------------------
-define(SERVER, ?MODULE).

%% --------------------------------------------------------------------
%% Records
%% --------------------------------------------------------------------

%% ====================================================================
%% External functions
%% ====================================================================
start_link()->
	supervisor:start_link({local,?MODULE}, ?MODULE, []).


%% ====================================================================
%% Server functions
%% ====================================================================
%% --------------------------------------------------------------------
%% Func: init/1
%% Returns: {ok,  {SupFlags,  [ChildSpec]}} |
%%          ignore                          |
%%          {error, Reason}
%% --------------------------------------------------------------------
init([]) ->
    {ok,{{one_for_one,10,10}, []}}.

start_child(Duration,Args)->	
	try
		AChild = {answer_processor ,{answer_processor,start_link,[Duration,Args]},
				  	      		transient,2000,worker,[answer_processor]},
		supervisor:start_child(?MODULE, AChild)
	catch
		E:R:_Stacktrace-> io:format("can not start activity_processor(~p:~p) ~p ~p ~n",[E,R,Duration,Args]),
			  {error,R}
 	end.

stop_child()->
	supervisor:terminate_child(?MODULE, answer_processor),
	supervisor:delete_child(?MODULE, answer_processor).

%% ====================================================================
%% Internal functions
%% ====================================================================
